<extend name="public@base"/>
block(name='main')
    .wrap.js-check-wrap
        ul.nav.nav-tabs
            li.nav-item
                a.nav-link(href!="{:url('NavMenu/index',['nav_id'=>$nav_id])}") 导航菜单
            li.nav-item
                a.nav-link.active {:lang('ADMIN_MENU_ADD')}
        form.form-horizontal.js-ajax-form.margin-top-20(method='post', action="{:url('NavMenu/addPost')}")
            fieldset
                .form-group.form-row
                    label.col-2.col-form-label.text-right 上级:
                    .col.col-lg-6
                        select.form-control(name='parent_id')
                            option(value='0') /
                            | {$nav_trees}
                .form-group.form-row
                    label.col-2.col-form-label.text-right
                        span.form-required
                        | 地址:
                    .col.col-lg-6.form-inline
                        input#external-link-radio(type='radio')
                        input#external-link-input.form-control(type='text', name='href')
                        input#select-href-radio(type='radio')
                        select#select-href.form-control(name='href')
                            option(value="{:base64_encode('home')}", data-name='首页') 首页
                            <foreach name="navs" item="vo">
                            optgroup(label='{$vo.name}')
                                | {$vo.html}
                            </foreach>
                .form-group.form-row
                    label.col-2.col-form-label.text-right
                        span.form-required *
                        | 菜单名称:
                    .col.col-lg-6
                        input#name-input.form-control(type='text', name='name')
                .form-group.form-row
                    label.col-2.col-form-label.text-right 打开方式:
                    .col.col-lg-6
                        select.form-control(name='target')
                            option(value='') 默认方式
                            option(value='_blank') 新窗口打开
                .form-group.form-row
                    label.col-2.col-form-label.text-right 图标:
                    .col.col-lg-6
                        input.form-control(type='text', name='icon', value='')
                .form-group.form-row
                    label.col-2.col-form-label.text-right 显示:
                    .col.col-lg-6
                        select.form-control(name='status')
                            option(value='1') 显示
                            option(value='0') 隐藏
                .form-group.form-row
                    .col-auto.offset-lg-2
                        input(type='hidden', name='nav_id', value='{$nav_id}')
                        button.btn.btn-sm.btn-primary.js-ajax-submit(type='submit') {:lang("SAVE")}
                        a.btn.btn-sm.btn-secondary(href!="{:url('NavMenu/index',['nav_id'=>$nav_id])}") 返回
block(name='bottom-script')
    script.
        $(function () {
            $("#select-href,#select-href-radio").click(function () {
                checkChange(2);
            });
            $("#select-href").change(function () {
                var $this = $(this);
                var label = $this.find("option[value='" + $this.val() + "']").data('name');
                $('#name-input').val(label);
            });
            $("#external-link-input,#external-link-radio").click(function () {
                checkChange(1);
            });
            function checkChange(i) {
                if (i == 1) {
                    //自动输入url
                    $('#external-link-input').attr('name', 'external_href');
                    $('#select-href').removeAttr('name');
                    $('#select-href-radio').prop('checked', false);
                    $('#external-link-radio').prop('checked', true);
                } else {
                    //选择链接url
                    $('#select-href').attr('name', 'href');
                    $('#external-link-input').removeAttr('name');
                    $('#select-href-radio').prop('checked', true);
                    $('#external-link-radio').prop('checked', false);
                }
            }
        });
